#pragma once
#include "nocopy.h"
#include "Socket.h"
#include "Channel.h"

#include <functional>
class EventLoop;
class InetAddress;
class Acceptor : nocopyable
{
public:
    using NewConnectionCallback = std::function<void(int sockfd, const InetAddress &)>;
    Acceptor(EventLoop *loop, const InetAddress &listenAddr, bool reuseport);
    ~Acceptor();
    void setNewConnectionCallback(const NewConnectionCallback &cb)
    {
        newConnectionCallback_ = cb;
    }
    bool listenning() const { return listenning_; }
    void listen();
private:
    void headleRead();
    EventLoop *loop_; // 这里是mainloop
    Socket acceptSocket_;
    Channel acceptChannel_;
    NewConnectionCallback newConnectionCallback_;
    bool listenning_;
};